-- Viral Resistance - T-Engine 4 Module
-- Copyright (C) 2010 Mikolai Fajer
--
-- This program is free software: you can redistribute it and/or modify
-- it under the terms of the GNU General Public License as published by
-- the Free Software Foundation, either version 3 of the License, or
-- (at your option) any later version.
--
-- This program is distributed in the hope that it will be useful,
-- but WITHOUT ANY WARRANTY; without even the implied warranty of
-- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
-- GNU General Public License for more details.
--
-- You should have received a copy of the GNU General Public License
-- along with this program.  If not, see <http://www.gnu.org/licenses/>.
--
-- Mikolai Fajer "yufra"
-- mfajer@gmail.com

-- Special AI for doctors in the opening scene
-- Moves about from patient to patient
newAI("doctor_patient", function(self)
	if self:runAI("injured_flee") then return true end
	-- If we are close to the current target, find a new one
	if not self.ai_target.actor or (self.ai_target.actor and core.fov.distance(self.x, self.y, 
	  self.ai_target.actor.x, self.ai_target.actor.y) < 4) then
		if rng.percent(70) then
			local patients = {}
			for i, v in pairs(game.level.entities) do
				if v.name and v.name == "patient" then
					table.insert(patients, v)
				end
			end
			self.ai_target.actor = rng.table(patients)
		else
			local nurses = {}
			for i, v in pairs(game.level.entities) do
				if v.name and v.name == "nurse" then
					table.insert(nurses, v)
				end
			end
			self.ai_target.actor = rng.table(nurses)
		end
	elseif self.ai_target.actor then
		self:runAI("move_simple")
	end
end)
